from __future__ import print_function
import ctypes, sys
import os
import time

def is_admin():
    try:
        return ctypes.windll.shell32.IsUserAnAdmin()
    except:
        return False
if is_admin():
    with os.popen(r'net start mysql5.7', 'r') as f:
        text = f.read()
        # 打开文件
        fo = open("log.txt", "a+",encoding='utf-8')
        """   localtime = time.localtime(time.time())
        """
        localtime =  (time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()))
        str="启动时间 :"+localtime+"\n" 
        fo.write(str+text)
        # 刷新缓冲区
        fo.flush()
        # 关闭文件
        fo.close()
else:
    if sys.version_info[0] == 3:
        ctypes.windll.shell32.ShellExecuteW(None, "runas", sys.executable, __file__, None, 1)
    else:#in python2.x
        ctypes.windll.shell32.ShellExecuteW(None, u"runas", unicode(sys.executable), unicode(__file__), None, 1)
















